$(function(){
    var sys_show_popup_login = $(".sys_show_popup_login"),
        sys_popup_common = $("#sys_popup_common");

    getTwitters('sys_lst_tweets', {
        id: 'megadrupal',
        count: 2,
        template: '<div class="tweet-item"><p class="rs tweet-mind">%text%</p><p class="rs timestamp">posted %time%</p></div>'
    });
    if ($("#slider1").length > 0) {
        $("#slider1").responsiveSlides({
            auto: false,
            pager: true,
            nav: true,
            speed: 500,
            maxwidth: 800,
            namespace: "centered-btns"
        });
    }


    $(".tabbable").on("click",".nav-tabs > li",function(){
        if($(this).hasClass("disable"))
            return false;
        var getIndex=$(this).index();
        $(this).siblings().removeClass("active").end().addClass("active");
        $(this).parents(".tabbable").find(".tab-content .tab-pane").removeClass("active").eq(getIndex).addClass("active");
        return false;
    });
    $(".accordion").on("click",".accordion-label",function(){
        if($(this).hasClass("active")){
            $(this).removeClass("active").siblings(".accordion-content").slideUp(400,function(){
                $(this).removeClass("active").removeAttr("style");
            });
        }else{
            $(this).parents(".accordion").find(".accordion-label").removeClass("active");
            $(this).addClass("active").siblings(".accordion-content").slideDown(400,function(){
                $(this).addClass("active").removeAttr("style");
            });
            $(this).parent().siblings().find(".accordion-content").slideUp(400,function(){
                $(this).removeClass("active").removeAttr("style");
            });
        }
        return false;
    });

    // Open popup when click to: Register, Login
    sys_show_popup_login.on("click",function(){
        sys_popup_common.fadeIn();
        $("body").on("keydown.closePopup",function(e){
            var getCode = e.keyCode ? e.keyCode : e.which;
            if(getCode == 27) {
                sys_popup_common.find(".closePopup").trigger("click");
            }
        });
        return false;
    });
    sys_popup_common.on("click.closePopup",".closePopup,.overlay-bl-bg",function(){
        sys_popup_common.fadeOut(function(){
            $("body").off("keydown.closePopup");
        });
    });
    sys_popup_common.on("click",".main-content",function(e){
        e.stopPropagation();
    });

    /*responsive*/
    var sys_btn_toggle_search = $("#sys_btn_toggle_search"),
        sys_header_right = $("#sys_header_right");
    sys_btn_toggle_search.on("click",function(){
        sys_header_right.slideToggle(function(){
            if($(this).is(":visible")){
                $(this).addClass("active");
            }else{
                $(this).removeClass("active");
            }
            $(this).removeAttr("style");
        });
        sys_btn_toggle_search.toggleClass("active");
    });

    // Sidr menu
    $('#btn-toogle-menu').sidr({
        side:"left",
        name:"alternate-menu",
        source:"#right-menu"
    });
    if ($("#sys-nav-menu-blog").length > 0) {
        selectnav("sys-nav-menu-blog");
    }
});